package com.hps.ssh.controller;

import com.hps.ssh.entity.Clazz;
import com.hps.ssh.entity.Student;
import com.hps.ssh.service.IClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/class")
public class ClassControler {

    @Autowired
    private IClassService classService;

    @RequestMapping("/add")
    public String add(Model model) {
        Clazz clazz = new Clazz();
        clazz.setName("计工1班");
        clazz.setLeader("王明");
        classService.addClass(clazz);
        model.addAttribute("tip", "class add success");
        return "success";
    }

    @RequestMapping("/{id}/get")
    @ResponseBody
    public Clazz get(@PathVariable("id") Integer id) {
        Clazz clazz = classService.findById(id);
        for(Student s: clazz.getStudents())
            System.out.println(s);
        return clazz;
    }
}
